package io.renren.modules.userdata.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.renren.common.utils.SnowFlakeIdGenerator;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.userdata.entity.TUserDataEntity;
import io.renren.modules.userdata.service.TUserDataService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author owen
 * @email zhaoouyang@qq.com
 * @date 2018-10-31 21:51:21
 */
@RestController
@RequestMapping("userdata/tuserdata")
public class TUserDataController {
    @Autowired
    private TUserDataService tUserDataService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("userdata:tuserdata:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tUserDataService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("userdata:tuserdata:info")
    public R info(@PathVariable("id") Long id){
        TUserDataEntity tUserData = tUserDataService.selectById(id);

        return R.ok().put("tUserData", tUserData);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("userdata:tuserdata:save")
    public R save(@RequestBody TUserDataEntity tUserData){
        tUserData.setId(SnowFlakeIdGenerator.getDefaultNextId());
        tUserData.setCreateTime(new Date());
        tUserDataService.insert(tUserData);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("userdata:tuserdata:update")
    public R update(@RequestBody TUserDataEntity tUserData){
        ValidatorUtils.validateEntity(tUserData);
        tUserData.setUpdateTime(new Date());
        tUserDataService.updateAllColumnById(tUserData);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("userdata:tuserdata:delete")
    public R delete(@RequestBody Long[] ids){
        tUserDataService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
